"""
@File    : loginPage.py
@Author  : qve-wzy
@Time    : 2020/9/2 0002 16:05
"""
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

from  util.read_ini import ReadIni
from  base.base_dirver import BaseDriver
from  util.get_local_data import GetByLocal

class LoginPage:
    '''
    登录页操作 page
    '''
    def __init__(self,i):
        '''
        初始化 driver
        读取ini中配置文件信息
        '''
        base_driver = BaseDriver()
        self.driver = base_driver.android_driver(i)
        print('driver -->初始化完毕，准备获取初始元素',self.driver)
        self.get_local_data = GetByLocal(self.driver)

    def one_login_element(self):
        '''
        获取用户名称元素的信息
        '''
        print('第一次登陆page')
        return self.get_local_data.get_element('go_login')

    def get_username_element(self):
        '''
        获取用户名称元素的信息
        '''
        return self.get_local_data.get_element('username')
    
    def get_password_element(self):
        '''
        获取密码元素的信息
        '''
        return self.get_local_data.get_element('password')

    def get_login_button_element(self):
        '''
        获取登陆按钮元素信息
        '''
        return self.get_local_data.get_element('login_button')

    def get_forget_password_element(self):
        '''
        忘记密码元素
        '''
        return self.get_local_data.get_element('forget_password')

    def get_register_element(self):
        '''
        注册元素
        '''
        return self.get_local_data.get_element('register')

    def get_tost_element(self, message):
        '''
        获取提示框信息
        '''
        time.sleep(2)
        tost_element = ("xpath", "//*[contains(@text," + message + ")]")
        return WebDriverWait(self.driver, 10, 0.1).until(EC.presence_of_element_located(tost_element))